#ifndef ARROW_H
#define ARROW_H

#include <QGraphicsItem>
#include <QPen>
#include "gen2/SemanticModel.h"

QT_BEGIN_NAMESPACE
class QGraphicsScene;
class QRectF;
class QPainterPath;
class QAction;
QT_END_NAMESPACE
	
class GraphScene;
class GraphNodeItem;

using SemanticModel::RelationType;

class Arrow : public QGraphicsItem
{
private:
	GraphScene *_scene;

public:
	Arrow(GraphScene *scene, GraphNodeItem *startItem,
		GraphNodeItem *endItem,
		SemanticModel::RelationType relationType = SemanticModel::NoneRelation,
		QGraphicsItem *parent = 0);
	virtual ~Arrow();
	enum { Type = UserType + 4 };
	int type() const { return Type; }

	QRectF boundingRect() const;
	QPainterPath shape() const;
	GraphNodeItem *startItem() const { return _startItem; }
	GraphNodeItem *endItem() const { return _endItem; }
	RelationType relation() const { return _relation; }
	
	void updatePosition();

protected:
	void paint(QPainter *painter, const QStyleOptionGraphicsItem *option,
			   QWidget *widget = 0);
	void contextMenuEvent(QGraphicsSceneContextMenuEvent *event);
	QString relationName() const;
	int relationNameWidth() const;
private:
	GraphNodeItem *_startItem;
	GraphNodeItem *_endItem;
	QLineF _line;
	QPen _pen;
	RelationType _relation;
	bool _fromClass;
	bool _toClass;
	static QMap<SemanticModel::RelationType, int> _relationMetrix;
	static int _textHeight;
	
	
	QPainterPath _lineShape;
	QPainterPath _selectionShape;
	QPainterPath _fullShape;
	QLineF _currentMetrix;

	friend class GraphNodeItem;
};

#endif